package com.sky.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.StringRedisSerializer;

@Slf4j
@Configuration
public class RedisConfiguration {

    @Bean
    public RedisTemplate redisTemplate(RedisConnectionFactory redisConnectionFactory){ //链接工厂对象
        log.info("开始创建redis的模板对象...");
        RedisTemplate template = new RedisTemplate();
        template.setConnectionFactory(redisConnectionFactory); //设置链接工厂对象
        //设置redis key 的序列化器
        template.setKeySerializer(new StringRedisSerializer()); //字符串的序列化器

        return template;
    }
}
